package com.wsc.frontier.database;

import java.io.File;
import java.io.FileNotFoundException;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;

public class DataBaseDetails {
	static String db_name,user,password,jdbc_url,jdbc_driver,master_table,url_table,wsdl_table,db_url;
	static XMLConfiguration config = null;
	
	public static void loadXmlFile() throws FileNotFoundException {
		File f;
		f = new File("config/DataBaseDetails.xml");
		try {
			config = new XMLConfiguration(f);

			// config.load();
		} catch (ConfigurationException e) {
			//e.printStackTrace();
		}
		// set expression engine to exexute xpath queries on config.xml file

		config.setExpressionEngine(new XPathExpressionEngine());
	}
	
	public static void getAllDetails(){
		db_name = (String) config
				.getProperty("/property/entry[@name='Database-Name']");
		
		user = (String) config
				.getProperty("/property/entry[@name='Databse-User']");
		
		password = (String) config
				.getProperty("/property/entry[@name='Database-Password']");
		
		jdbc_url = (String) config
				.getProperty("/property/entry[@name='JDBC-URL']");
		
		db_url = (String) config
				.getProperty("/property/entry[@name='JDBC-DB-URL']");
		
		jdbc_driver = (String) config
				.getProperty("/property/entry[@name='Database-Driver']");
		
		master_table = (String) config
				.getProperty("/property/entry[@name='Master-Table']");
		
		url_table = (String) config
				.getProperty("/property/entry[@name='URLs-Table']");
		
		wsdl_table = (String) config
				.getProperty("/property/entry[@name='WSDL-Table']");
	}
	
	public static String getMasterTable() {
		return master_table;
	}

	
	public static String getURLsTable() {
		return url_table;
	}
	
	public static String getWSDLTable() {
		return wsdl_table;
	}
	
	
	
	public static String getDatabaseName() {
		return db_name;
	}
	
	public static String getDatabaseUser(){
		return user;
	}
	
	public static String getDatabasePassword(){
		
		// null check for password
		if(password != null && !password.trim().isEmpty())
		return password;
		else
			return "";
	}
	
	public static String getJdbcUrl(){
		return jdbc_url;
	}
	
	public static String getDbUrl(){
		return db_url;
	}
	
	public static String getDatabaseDriver(){
		return jdbc_driver;
	}
	
	

}
